package com.shouxin.attendance.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Locale;

/**
 * <p>时间工具类</p>
 * Created by Jiang on 2015/10/25.
 */
public final class TimeUtils {

    private TimeUtils() {

    }

    public static boolean isAM() {
        GregorianCalendar calendar = new GregorianCalendar();
        return calendar.get(Calendar.AM_PM) == 0;
    }

    public static String getTimeString(long timeStamp) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());

        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(timeStamp);

        return format.format(calendar.getTime());
    }

    public static long getOffsetTime(int historyKeepDay) {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, -historyKeepDay);
        return calendar.getTimeInMillis();
    }

    public static int getTimeType(long timeStamp) {
        SimpleDateFormat format = new SimpleDateFormat("HHmm", Locale.getDefault());
        return Integer.valueOf(format.format(timeStamp));
    }

    public static int getWeek(long time) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(time);
        return calendar.get(Calendar.DAY_OF_WEEK);
    }
}
